#Charles S. Bullock, III, William D. Hicks, 
#M.V. Hood, III, Seth C. McKee, and Daniel A. Smith
#"The Election of African American State Legislators in the Modern South" in LSQ

#THIS FILE REPRODUCES FIGURE A2 IN ONLINE APPENDIX


rm(list=ls())


#SET A WORKING DIRECTORY TO SAVE FIGURE
setwd("[MAKE DIRECATORY HERE]")

#LOAD DATASET FIGURE_A2.Rdata
load("~[FILE PATH]/FIGURE_A2.Rdata")

#BUILD THE FIGURE

png('FIGURE_A2.png', width=900, height=700, pointsize=16)
par(mfrow=c(4,3), mar=c(3,3,2,2))

#Alabama

plot(matrix(mat[1, c(2:6)]), main='AL', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[1,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)


#Arkansas

plot(matrix(mat[2, c(2:6)]), main='AR', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[2,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

#Florida

plot(matrix(mat[3, c(2:6)]), main='FL', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[3,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

#Georgia

plot(matrix(mat[4, c(2:6)]), main='GA', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[4,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

#Louisiana

plot(matrix(mat[5, c(2:6)]), main='LA', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[5,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)


#Mississippi

plot(matrix(mat[6, c(2:6)]), main='MS', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[6,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

#North Carolina

plot(matrix(mat[7, c(2:6)]), main='NC', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[7,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

#South Carolina

plot(matrix(mat[8, c(2:6)]), main='SC', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[8,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

##Tennessee

plot(matrix(mat[9, c(2:6)]), main='TN', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[9,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

##Texas

plot(matrix(mat[10, c(2:6)]), main='TX', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[10,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

#Virginia

plot(matrix(mat[11, c(2:6)]), main='VA', type='o', cex.main=1.5, pch=16, ylim=c(0,.75), cex=2, lwd=2, lty=1, cex.lab=6, axes=FALSE, xlab="", ylab="")
lines(matrix(mat[11,c(7:11)]), type="o", pch=15, lty=1, lwd=2, cex=2)
axis(2, at=c(0,.25,.5,.75), labels=c('0%','25%','50%','75%'))
axis(1, at=c(1:5), lab=c('70s','80s','90s','00s','10s'), cex=1)

plot(1, axes=FALSE, type = "n", xlab='', ylab='',,bty = "n", xaxt = "n", yaxt = "n")

legend('top', inset=c(0,-.05), c('% GOP','% Black'), cex=2.5, 
       pt.cex=3.5, col=c('black','black'), pch=c(15,16), bty='n')

dev.off()

